﻿package com.wandian.view.components.ui
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.AccountProxy;
	import com.wandian.model.vo.FaceVo;
	import com.wandian.model.vo.PropVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.ToolTip;

	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class PayBagPanel extends Object
	{
		private var facade:ApplicationFacade;
		private var _global:GameData;
		private var _filter:GlowFilterManage;
		private var _mcPanel:Sprite;
		private var _arrXML:Array;

		public function PayBagPanel(param1:Sprite, param2:Object)
		{
			var _loc_6:String=null;
			var _loc_7:PayBagVo=null;
			var _loc_8:int=0;
			var _loc_9:Array=null;
			var _loc_10:PropVo=null;
			this.facade=ApplicationFacade.getInstance();
			this._global=GameData.getInstance();
			this._filter=GlowFilterManage.getInstance();
			this._mcPanel=param1;
			this._mcPanel["close_btn"].addEventListener(MouseEvent.CLICK, this.onCloseHandler);
			this._mcPanel["pay_btn"].addEventListener(MouseEvent.CLICK, this.onPayHandler);
			this._arrXML=getChargeXML(param2);
			var _loc_3:*=this._arrXML.length;
			ToolTip.stage=Texas.I._mcTipView.stage;
			var _loc_4:Array=[];
			var _loc_5:int=0;
			while (_loc_5 < _loc_3)
			{

				_loc_7=this._arrXML[_loc_5] as PayBagVo;
				if (_loc_5 == 0)
				{
					this._mcPanel["time_txt"].htmlText=GameData.replaceStrValue(GameData.tip["PAY_BAG_TIME_TIP"], "TIME", GameData.setDate(_loc_7.etime));
				}
				if (_loc_7.type == 1)
				{
					_loc_4.push(0);
					this._mcPanel["txt" + _loc_7.id].htmlText=GameData.tip["PAY_BAG_TIP_1"];
				}
				else
				{
					if (this._global.userInfo.userVo.gp != GameData.QZONE_SID)
					{
					}
					if (this._global.userInfo.userVo.gp == GameData.FRIEND_SID)
					{
						_loc_4.push(_loc_7.mincharge * 10);
						this._mcPanel["txt" + _loc_7.id].htmlText=GameData.replaceStrValue(GameData.tip["PAY_BAG_TIP_Q"], "NUM", _loc_7.mincharge * 10);
					}
					else
					{
						_loc_4.push(_loc_7.mincharge);
						this._mcPanel["txt" + _loc_7.id].htmlText=GameData.replaceStrValue(GameData.tip["PAY_BAG_TIP_2"], "NUM", _loc_7.mincharge);
					}
				}
				_loc_6="";
				_loc_8=0;
				while (_loc_8 < _loc_7.arrContent.length)
				{

					_loc_9=String(_loc_7.arrContent[_loc_8]).split("-");
					if (_loc_9[0] == 1)
					{
						_loc_6=_loc_6 + (" " + _loc_9[1] + GameData.tip["GOLD"] + "   \n");
					}
					else
					{
						_loc_10=GameData.getPropById(_loc_9[1], _loc_9[2]);
						_loc_6=_loc_6 + (" " + _loc_10.name + " x " + _loc_9[3] + "   \n");
					}
					_loc_8=_loc_8 + 1;
				}
				ToolTip.setDOInfo(this._mcPanel["bag" + _loc_7.id], _loc_6);
				this._mcPanel["bag" + _loc_7.id].addEventListener(MouseEvent.MOUSE_OVER, this.overHandler);
				this._mcPanel["bag" + _loc_7.id].addEventListener(MouseEvent.MOUSE_OUT, this.outHandler);
				if (_loc_7.state == 0)
				{
					CLZButton.setButton(this._mcPanel["ok" + _loc_7.id + "_btn"], GameData.tip["CONDITION_ERR"]);
					CLZButton.enabled(this._mcPanel["ok" + _loc_7.id + "_btn"], false, 1);
				}
				else if (_loc_7.state == 1)
				{
					CLZButton.setButton(this._mcPanel["ok" + _loc_7.id + "_btn"], GameData.tip["DRAW_PRIZE"]);
					CLZButton.enabled(this._mcPanel["ok" + _loc_7.id + "_btn"], true);
				}
				else
				{
					CLZButton.setButton(this._mcPanel["ok" + _loc_7.id + "_btn"], GameData.tip["NO_PRIZE"]);
					CLZButton.enabled(this._mcPanel["ok" + _loc_7.id + "_btn"], false, 1);
				}
				this._mcPanel["ok" + _loc_7.id + "_btn"].id=_loc_7.id;
				this._mcPanel["ok" + _loc_7.id + "_btn"].addEventListener(MouseEvent.CLICK, this.onHandler);
				_loc_5=_loc_5 + 1;
			}
			_loc_6="";
			_loc_5=0;
			while (_loc_5 < _loc_4.length)
			{

				if (this._global.userInfo.userVo.tcost == 0)
				{
				}
				if (_loc_4[_loc_5] == 0)
				{
					if (this._global.userInfo.userVo.gp != GameData.QZONE_SID)
					{
					}
					if (this._global.userInfo.userVo.gp == GameData.FRIEND_SID)
					{
						_loc_6=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["PAY_BAG_TIP_Q_TOP"], "NUM", this._global.userInfo.userVo.tcost), "NUM1", 100);
					}
					else
					{
						_loc_6=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["PAY_BAG_TIP_RMB_TOP"], "NUM", this._global.userInfo.userVo.tcost), "NUM1", 10);
					}
					break;
				}
				else if (this._global.userInfo.userVo.tcost < _loc_4[_loc_5])
				{
					if (this._global.userInfo.userVo.gp != GameData.QZONE_SID)
					{
					}
					if (this._global.userInfo.userVo.gp == GameData.FRIEND_SID)
					{
						_loc_6=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["PAY_BAG_TIP_Q_TOP"], "NUM", this._global.userInfo.userVo.tcost), "NUM1", _loc_4[_loc_5] - this._global.userInfo.userVo.tcost);
					}
					else
					{
						_loc_6=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["PAY_BAG_TIP_RMB_TOP"], "NUM", this._global.userInfo.userVo.tcost), "NUM1", _loc_4[_loc_5] - this._global.userInfo.userVo.tcost);
					}
					break;
				}
				_loc_5=_loc_5 + 1;
			}
			if (_loc_6 == "")
			{
				this._mcPanel["tip_txt"].htmlText=GameData.tip["PAY_BAG_TIP_TOP"];
			}
			else
			{
				this._mcPanel["tip_txt"].htmlText=_loc_6;
			}
			return;
		} 

		public function drawPayBagres(param1:Array):void
		{
			var _loc_2:*=param1[2];
			CLZButton.updateMcText(this._mcPanel["ok" + _loc_2 + "_btn"], GameData.tip["NO_PRIZE"]);
			CLZButton.enabled(this._mcPanel["ok" + _loc_2 + "_btn"], false, 1);
			return;
		} 

		private function onHandler(event:MouseEvent):void
		{
			var _loc_2:*=event.target.id;
			trace(event.target.id);
			CLZButton.updateMcText(this._mcPanel["ok" + _loc_2 + "_btn"], GameData.tip["NO_PRIZE"]);
			CLZButton.enabled(this._mcPanel["ok" + _loc_2 + "_btn"], false, 1);
			this.facade.sendNotification(CLZNoticeName.DRAW_PAY_BAG_REQ, _loc_2);
			return;
		} 

		private function overHandler(event:MouseEvent):void
		{
			ToolTip.showToolTip();
			return;
		} 

		private function outHandler(event:MouseEvent):void
		{
			ToolTip.hideToolTip();
			return;
		} 

		private function onPayHandler(event:MouseEvent):void
		{
			this.facade.sendNotification(CLZNoticeName.ON_PAY_VIP);
			return;
		} 

		private function onCloseHandler(event:MouseEvent):void
		{
			this.facade.sendNotification(CLZNoticeName.HIDE_PAY_BAG_PANEL);
			return;
		} 

		public static function getChargeXML(param1:Object):Array
		{
			var _loc_5:PayBagVo=null;
			var _loc_2:*=GameData.commonXML.charge.item;
			var _loc_3:Array=[];
			var _loc_4:uint=0;
			while (_loc_4 < _loc_2.length())
			{

				_loc_5=new PayBagVo();
				_loc_5.id=_loc_2[_loc_4].@id;
				_loc_5.type=_loc_2[_loc_4].@type;
				_loc_5.mincharge=_loc_2[_loc_4].@mincharge;
				_loc_5.arrContent=String(_loc_2[_loc_4].@content).split(",");
				_loc_5.etime=_loc_2[_loc_4].@etime;
				_loc_5.state=param1[_loc_5.id];
				_loc_3.push(_loc_5);
				_loc_4=_loc_4 + 1;
			}
			return _loc_3;
		} 

	}
}

class PayBagVo extends Object
{
	public var id:int;
	public var type:int;
	public var mincharge:int;
	public var arrContent:Array;
	public var etime:uint;
	public var state:int;

	function PayBagVo():void
	{
		return;
	} 

}

